/**
 * 精度在1E6、7左右大概可算，否则就T了
 * 最大数据为1E3，配上精度1E-9，需要计算1E12，必须使用公式法。
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using Real = long double;
using llt = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

#ifndef ONLINE_JUDGE
int const SZ = 34;
#else
int const SZ = 200000 + 12;
#endif

Real const EPS = 1E-9;
inline int sgn(Real x){return x >= EPS ? 1 : (x <= -EPS ? -1 : 0);}
inline bool is0(Real x){return 0 == sgn(x);}

struct RombergInt{

RombergInt() = delete;
RombergInt(function<Real(Real)> func, Real epsi, const pair<Real, Real> range, int sz=1000)
:f(func), eps(epsi), bound(range), result(0.)
{
    this->result = this->calc(sz);
}

Real getResult() const {return this->result;}

Real calc(int sz) {
    this->r.clear();
    this->r.reserve(sz);
    auto x1 = this->bound.first, x2 = this->bound.second;
    auto h = x2 - x1;
    long long m = 1;
    this->r.push_back(
        {0.5 * h * (this->f(x1) + this->f(x2)), 0., 0., 0.}
    );

    for(int i=1;;++i){
        this->r.push_back({0.0, 0.0, 0.0, 0.0});
        auto & now = r[i];
        auto & prev = r[i - 1];
        auto h2 = h;
        h *= 0.5, m <<= 1;

        auto x = x1 + h;
        auto & sum = now[0];
        for(int j=1;j<m;j+=2){
            sum += this->f(x);
            x += h2;
        }
        sum = 0.5 * prev[0] + h * sum;
        
        now[1] = (4.0 * now[0] - prev[0]) / 3.0;
        now[2] = (16.0 * now[1] - prev[1]) / 15.0;
        now[3] = (64.0 * now[2] - prev[2]) / 63.0;
        if(fabs(prev[3] - now[3]) <= this->eps) return now[3];
    }
    throw runtime_error("XXXXX");
}

private:
function<Real(Real)> f;
Real const eps;
pair<Real, Real> const bound;
Real result;
vector<array<Real, 4>> r;

};

struct Point{
    Real x, y;
    
    Point(Real u=0,Real v=0):x(u),y(v){}

    Real cross(const Point & r) const {
        return this->x * r.y - r.x * this->y;
    }

    Real dot(const Point & r) const {
        return this->x * r.x + this->y * r.y;
    }

    Point & operator -= (const Point & r){
        this->x -= r.x;
        this->y -= r.y;
        return *this;
    }

    const Point operator - (const Point & r) const {
        return {this->x - r.x, this->y - r.y};
    }

    bool is0() const {
        return ::is0(this->x) and ::is0(this->y);
    }
};

Real cross(const Point & O, const Point & A, const Point & B){
    auto xoa = A.x - O.x, yoa = A.y - O.y;
    auto xob = B.x - O.x, yob = B.y - O.y;
    return xoa * yob - xob * yoa;
}

Point A, B, C, D;

inline Point rotate(const Point & p, Real cosValue, Real sinValue){
    return {
        cosValue * p.x - sinValue * p.y,
        sinValue * p.x + cosValue * p.y
    };
}

void transformBy(Point & o, Point & another, Point & u, Point & v){
    another -= o;
    u -= o;
    v -= o;
    o = {0., 0.};

    Real theta = atan2(another.y, another.x);
    theta = - theta;

    Real cosTheta = cos(theta);
    Real sinTheta = sin(theta);

    another = rotate(another, cosTheta, sinTheta);
    u = rotate(u, cosTheta, sinTheta);
    v = rotate(v, cosTheta, sinTheta);

    return;
}

void transform(Point & A, Point & B, Point & C, Point & D){
    vector<Point> origin = {A, B, C, D};

    auto tmp = sgn((B - A).cross(D - C));
    assert(tmp);

    if(tmp < 0){
        swap(A, C);
        swap(B, D);
    }

    transformBy(A, B, C, D);
    assert(A.is0());
    // assert(is0(B.y) and sgn(B.x) > 0);
    if(not (is0(B.y) and sgn(B.x) > 0)){
        stringstream s;
        for(const auto & p : origin){
            s << fixed << setprecision(0) << "(" << p.x << ", " << p.y << ")";
        }
        throw runtime_error(s.str().c_str());
    }
    assert(is0(C.x - D.x));
    assert(sgn(D.y - C.y) > 0);

    return;
}

Real proc(){
    assert(is0((B - A).dot(D - C)));
    transform(A, B, C, D);

    A.x -= C.x;
    B.x -= C.x;
    C.x = D.x = 0;

    if(sgn(B.x) <= 0){
        A.x = -A.x;
        B.x = -B.x;
        swap(A.x, B.x);
    }

    if(sgn(D.y) <= 0){
        C.y = -C.y;
        D.y = -D.y;
        swap(C.y, D.y);
    }

    assert(is0(A.y) and is0(B.y) and is0(C.x) and is0(D.x));
    assert(sgn(D.y) > 0 and sgn(D.y - C.y) > 0 and sgn(B.x) > 0 and sgn(B.x - A.x) > 0);
    
    auto f = [](Real x, Real y){
        if(is0(x)) x = 0;
        auto fang = x * x;
        if(is0(y)) y = 0;
        auto gen = sqrt(fang + y * y);
        if(is0(gen)) gen = 0;
        if(is0(fang)) return 0.5 * y * gen;
        return 0.5 * (y * gen + fang * log(y + gen));
    };

    Real ans = 0;
    if(sgn(C.y) >= 0){
        if(sgn(A.x) >= 0){
            ans = RombergInt(
                [&](Real x){return f(x, D.y) - f(x, C.y);},
                EPS,
                {A.x, B.x}
            ).getResult();            
        }else{
            ans = RombergInt(
                [&](Real x){return f(x, D.y) - f(x, C.y);},
                EPS,
                {0.0, B.x}
            ).getResult();   
            ans += RombergInt(
                [&](Real x){return f(x, D.y) - f(x, C.y);},
                EPS,
                {0.0, -A.x}
            ).getResult();   
        }
    }else{
        if(sgn(A.x) >= 0){
            ans = RombergInt(
                [&](Real x){return f(x, D.y) - f(x, 0.);},
                EPS,
                {A.x, B.x}
            ).getResult(); 
            ans += RombergInt(
                [&](Real x){return f(x, -C.y) - f(x, 0.);},
                EPS,
                {A.x, B.x}
            ).getResult(); 
        }else{
            ans = RombergInt(
                [&](Real x){return f(x, D.y) - f(x, 0);},
                EPS,
                {0.0, B.x}
            ).getResult();   
            ans += RombergInt(
                [&](Real x){return f(x, D.y) - f(x, 0);},
                EPS,
                {0.0, -A.x}
            ).getResult(); 
            ans += RombergInt(
                [&](Real x){return f(x, -C.y) - f(x, 0.);},
                EPS,
                {0.0, B.x}
            ).getResult(); 
            ans += RombergInt(
                [&](Real x){return f(x, -C.y) - f(x, 0.);},
                EPS,
                {0.0, -A.x}
            ).getResult(); 
        }
    }
    ans /= (B.x - A.x) * (D.y - C.y);
    return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase; cin >> nofkase;
    while(nofkase--){
        cin >> A.x >> A.y >> B.x >> B.y >> C.x >> C.y >> D.x >> D.y;
        cout << fixed << setprecision(23) << proc() << endl;
    }
    return 0;
}
